#pragma once

#include <stdio.h>
#include <Windows.h>
#include <dsound.h>
#include "Structures.h"
#include "sound_manager.h"


class iSound
{
private:
	HRESULT hResult;

protected:
	/* Variables */

	LPWSTR fileName;
	LPDIRECTSOUNDBUFFER8 buffer8;
	SoundManager *soundManager;
	int bufferSize;
	HANDLE threadHandle; // thread handle
	HANDLE fileHandle; // sound file handle
	LPVOID mapPointer;
	unsigned long fileLength;
	// Fill buffer control member
	//
	DWORD playPos;
	DWORD writePos;
	DWORD prevPlayPos;
	bool firstFillBuffer;
	// Playback control member
	bool loop;
	enum PlayState playState;

	/* Function */

	void Prepare();
	// write data to buffer
	void WriteData(LPBYTE lpData, // pointer to input buffer
    DWORD dwOffSet, // offset of directsound buffer begin write
    DWORD dwSoundByte);


public:
	/* Common interfaces*/

	void Play(bool loop);
	void Pause();
	void Stop();

	/* Constructor, destructor */

	iSound(LPWSTR, SoundManager*);
	iSound(void);
	~iSound(void);
};

